<?php

namespace App\Common\Dao\System;

use App\Common\Dao\BaseDao;
use App\Model\CustomerAdmin;

class CustomerAdminDao extends BaseDao
{
    protected function getModel(): CustomerAdmin
    {
        return new CustomerAdmin();
    }

    public function search(array $where){
        return CustomerAdmin::when(isset($where['status']) && $where['status'] != ''  , function ($query) use ($where) {
            $query->where('status', $where['status']);
        })
            ->when(isset($where['username']) && $where['username'] != ''  , function ($query) use ($where) {
                $query->where('username', 'like', "%" .$where['username']. "%");
            })
            ->when(isset($where['email']) && $where['email'] != ''  , function ($query) use ($where) {
                $query->where('email', 'like', "%" .$where['email']. "%");
            })
            ->when(isset($where['no_admin']) && $where['no_admin'] != ''  , function ($query) use ($where) {
                $query->whereNotIn('id', $where['no_admin']);
            });
    }
}